function addArduinoCod(Blockly) {

    Blockly.Arduino['huskyLensSenso_init'] = function (block) {
        let rx_pin = this.getFieldValue('rx_pin');
        let tx_pin = this.getFieldValue('tx_pin');

        Blockly.Arduino.definitions_['include_huskyLensSenso_init'] = `\n#include <DFRobot_HuskyLens.h>\n`;
        Blockly.Arduino.definitions_['define_huskyLensSenso_init'] = `DFRobot_HuskyLens huskylens;\n`;
        
        return `huskylens.beginSoftwareSerialUntilSuccess(${rx_pin}, ${tx_pin});\n`;
    }

    Blockly.Arduino['huskyLensSenso_setMode'] = function (block) {
        let mode = this.getFieldValue('mode');
        
        return `huskylens.writeAlgorithm(${mode});\n`;
    }

    Blockly.Arduino['huskyLensSenso_request'] = function (block) {

        return `huskylens.request();\n`;
    }

    Blockly.Arduino['huskyLensSenso_readLearnedIDCount'] = function (block) {

        return [`huskylens.readLearnedIDCount()`];
    }

    Blockly.Arduino['huskyLensSenso_isAppearDirect'] = function (block) {
        let type = this.getFieldValue('type');

        return [`huskylens.isAppearDirect(${type})`];
    }

    Blockly.Arduino['huskyLensSenso_readBlockCenterParameterDirect'] = function (block) {
        let type = this.getFieldValue('type');

        return [`huskylens.readBlockCenterParameterDirect().${type}`];
    }

    Blockly.Arduino['huskyLensSenso_readArrowCenterParameterDirect'] = function (block) {
        let type = this.getFieldValue('type');

        return [`huskylens.readArrowCenterParameterDirect().${type}`];     
    }

    Blockly.Arduino['huskyLensSenso_isLearned'] = function (block) {
        let id =  Blockly.Arduino.valueToCode(this, 'id', Blockly.Arduino.ORDER_ATOMIC);
        return [`huskylens.isLearned(${id})`];     
    }

    Blockly.Arduino['huskyLensSenso_isAppear'] = function (block) {
        let type = this.getFieldValue('type');
        let id =  Blockly.Arduino.valueToCode(this, 'id', Blockly.Arduino.ORDER_ATOMIC);

        return [`huskylens.isAppear(${id}, ${type})`];     
    }

    Blockly.Arduino['huskyLensSenso_readBlockParameter'] = function (block) {
        let type = this.getFieldValue('type');
        let id =  Blockly.Arduino.valueToCode(this, 'id', Blockly.Arduino.ORDER_ATOMIC);

        return [`huskylens.readBlockParameter(${id}).${type}`];     
    }

    Blockly.Arduino['huskyLensSenso_readArrowParameter'] = function (block) {
        let type = this.getFieldValue('type');
        let id =  Blockly.Arduino.valueToCode(this, 'id', Blockly.Arduino.ORDER_ATOMIC);

        return [`huskylens.readArrowParameter(${id}).${type}`];     
    }

    Blockly.Arduino['huskyLensSenso_readCount'] = function (block) {
        let type = this.getFieldValue('type');

        return [`huskylens.readCount(${type})`];     
    }

    Blockly.Arduino['huskyLensSenso_readBlockParameterDirect'] = function (block) {
        let type = this.getFieldValue('type');
        let id =  Blockly.Arduino.valueToCode(this, 'id', Blockly.Arduino.ORDER_ATOMIC);

        return [`huskylens.readBlockParameterDirect(${id}).${type}`];     
    }

    Blockly.Arduino['huskyLensSenso_readArrowParameterDirect'] = function (block) {
        let type = this.getFieldValue('type');
        let id =  Blockly.Arduino.valueToCode(this, 'id', Blockly.Arduino.ORDER_ATOMIC);

        return [`huskylens.readArrowParameterDirect(${id}).${type}`];     
    }

    Blockly.Arduino['huskyLensSenso_idReadCount'] = function (block) {
        let type = this.getFieldValue('type');
        let id =  Blockly.Arduino.valueToCode(this, 'id', Blockly.Arduino.ORDER_ATOMIC);

        return [`huskylens.readCount(${id}, ${type})`];     
    }

    Blockly.Arduino['huskyLensSenso_idReadBlockParameter'] = function (block) {
        let type = this.getFieldValue('type');
        let id =  Blockly.Arduino.valueToCode(this, 'id', Blockly.Arduino.ORDER_ATOMIC);
        let no =  Blockly.Arduino.valueToCode(this, 'no', Blockly.Arduino.ORDER_ATOMIC);

        return [`huskylens.readBlockParameter(${id}, ${no}).${type}`];     
    }

    Blockly.Arduino['huskyLensSenso_idReadArrowParameter'] = function (block) {
        let type = this.getFieldValue('type');
        let id =  Blockly.Arduino.valueToCode(this, 'id', Blockly.Arduino.ORDER_ATOMIC);
        let no =  Blockly.Arduino.valueToCode(this, 'no', Blockly.Arduino.ORDER_ATOMIC);

        return [`huskylens.readArrowParameter(${id}, ${no}).${type}`];     
    }

    Blockly.Arduino['huskyLensSenso_learnOnece'] = function (block) {
        let id =  Blockly.Arduino.valueToCode(this, 'id', Blockly.Arduino.ORDER_ATOMIC);

        return `huskylens.learnOnece(${id});\n`;     
    }

    Blockly.Arduino['huskyLensSenso_forgetLearn'] = function (block) {
        return `huskylens.forgetLearn();\n`;     
    }

    Blockly.Arduino['huskyLensSenso_writeName'] = function (block) {
        let id =  Blockly.Arduino.valueToCode(this, 'id', Blockly.Arduino.ORDER_ATOMIC);
        let na = Blockly.Arduino.valueToCode(this, 'na', Blockly.Arduino.ORDER_ATOMIC);
        
        return `huskylens.writeName(String("${na}"), ${id});\n`;     
    }

    Blockly.Arduino['huskyLensSenso_writeOSD'] = function (block) {
        let na =  Blockly.Arduino.valueToCode(this, 'na', Blockly.Arduino.ORDER_ATOMIC);
        let x =  Blockly.Arduino.valueToCode(this, 'x', Blockly.Arduino.ORDER_ATOMIC);
        let y = Blockly.Arduino.valueToCode(this, 'y', Blockly.Arduino.ORDER_ATOMIC);
        
        return `huskylens.writeOSD(String("${na}"), ${x}, ${y});\n`;     
    }

    Blockly.Arduino['huskyLensSenso_clearOSD'] = function (block) {        
        return `	huskylens.clearOSD();\n`;     
    }

    Blockly.Arduino['huskyLensSenso_takePhotoToSDCard'] = function (block) {
        let type = this.getFieldValue('type');

        return `huskylens.${type}();\n`;     
    }

    Blockly.Arduino['huskyLensSenso_saveModelToTFCard'] = function (block) {
        let type = this.getFieldValue('type');
        let no = this.getFieldValue('no');

        return `huskylens.${type}(${no});\n`;     
    }

    return Blockly;
}

module.exports = addArduinoCod;

